package _03xml解析_案例;

import com.sun.org.apache.xpath.internal.operations.Bool;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class Demo3 {
    public static void main(String[] args) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read("Day_14\\contact.xml");
        Element root = document.getRootElement();
        List<Element> eles = root.elements();
        ArrayList<Contact> con = new ArrayList<>();
        for (Element ele : eles) {
            String idStr = ele.attributeValue("id");
            int id = Integer.parseInt(idStr);

            String vipStr = ele.attributeValue("vip");
            boolean vip = Boolean.parseBoolean(vipStr);

            String name = ele.element("name").getText();
            String gender = ele.element("gender").getText();
            String email = ele.element("email").getText();

            Contact c = new Contact(id,vip,name,gender,email);
            con.add(c);


        }
        for (Contact c : con) {
            System.out.println(c);
        }
    }
}
